package com.css.zfzx.sjcj.common.excel.util;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import com.css.bpm.platform.utils.PlatformObjectUtils;
import com.css.zfzx.sjcj.common.division.MunicipalityEnums;
import com.css.zfzx.sjcj.common.excel.entity.ActiveFaultVerifyExcelBaseModel;
import org.springframework.stereotype.Component;

@Component
public class ActiveFaultEasyExcelVerifyHelper {

    public ExcelVerifyHandlerResult verify(ActiveFaultVerifyExcelBaseModel base) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult(true);
        if (PlatformObjectUtils.isEmpty(base.getVId())) {
            writeNotNullMsg(result, "编号");
            return result;
        } else if (!MunicipalityEnums.isMunicipality(base.getVCity()) // 非直辖市
                && PlatformObjectUtils.isEmpty(base.getVProvince())) {
            result.setMsg("非直辖市时, 省不能为空(请确认是否为城市全称)");
            result.setSuccess(false);
            return result;
        } else if (PlatformObjectUtils.isEmpty(base.getVCity())) {
            writeNotNullMsg(result, "市");
            return result;
        } else if (PlatformObjectUtils.isEmpty(base.getVArea())) {
            writeNotNullMsg(result, "区(县)");
            return result;
        } else if (PlatformObjectUtils.isEmpty(base.getVProjectName())) {
            writeNotNullMsg(result, "项目名称");
            return result;
        } else if (PlatformObjectUtils.isEmpty(base.getVTaskName())) {
            writeNotNullMsg(result, "任务名称");
            return result;
        } else {
            String id = base.getVId();
            if (id.length() != 17) {
                result.setMsg("编号长度应为17位");
                result.setSuccess(false);
                return result;
            }
        }
        return result;
    }

    public void writeNotNullMsg(ExcelVerifyHandlerResult result, String fieldName) {
        result.setMsg(fieldName + "不能为空");
        result.setSuccess(false);
    }

}
